/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.user;

import model.Campaign;
import java.util.ArrayList;
import java.util.Iterator;
import model.Appointment;
import model.ConsultedCampaign;
import model.ScheduleEntry;
import model.Skill;
import model.Task;

/**
 *
 * @author CUNEYT
 */
public class Staff extends User {

    private ArrayList<ConsultedCampaign> consultedCampaigns = null;
    private ArrayList<Skill> skills = null;
    private ArrayList<ScheduleEntry> schedule = null;
    private String department = null;

    public Staff(String name, String surname, String username, char[] password) {
        super(name, surname, username, password, User.STAFF);
        consultedCampaigns = new ArrayList<ConsultedCampaign>();
        skills = new ArrayList<Skill>();
        schedule = new ArrayList<ScheduleEntry>();
    }

    public Staff(String name, String surname, String username, char[] password, String dep) {
        super(name, surname, username, password, User.STAFF);
        department = dep;
        consultedCampaigns = new ArrayList<ConsultedCampaign>();
        skills = new ArrayList<Skill>();
        schedule = new ArrayList<ScheduleEntry>();
    }

    public void removeConsultedCampaign(ConsultedCampaign cc) {
        this.consultedCampaigns.remove(cc);
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public ArrayList<ScheduleEntry> getSchedule() {
        return schedule;
    }

    public void setSchedule(ArrayList<ScheduleEntry> schedule) {
        this.schedule = schedule;
        setChanged();
    }

    public void addSkill(Skill s) {
        if (!skills.contains(s)) {
            skills.add(s);
            setChanged();
        }
    }

    public ArrayList<Skill> getSkills() {
        return skills;
    }

    public void setSkills(ArrayList<Skill> skills) {
        this.skills = skills;
        setChanged();
    }

    public void addAppointment(Appointment a) {
        if (!schedule.contains(a)) {
            schedule.add(a);
            setChanged();
        }
    }

    public void addTask(Task t) {
        if (!schedule.contains(t)) {
            schedule.add(t);
            setChanged();
        }
    }

    public ArrayList<Task> getTasks() {
        ArrayList<Task> result = new ArrayList<Task>();
        for (Iterator<ScheduleEntry> it = schedule.iterator(); it.hasNext();) {
            ScheduleEntry entry = it.next();
            if (entry instanceof Task) {
                result.add((Task) entry);
            }
        }
        return result;
    }

    public ArrayList<Appointment> getAppointments() {
        ArrayList<Appointment> result = new ArrayList<Appointment>();
        for (Iterator<ScheduleEntry> it = schedule.iterator(); it.hasNext();) {
            ScheduleEntry entry = it.next();
            if (entry instanceof Appointment) {
                result.add((Appointment) entry);
            }
        }
        return result;
    }

    public void addInOfficeHour(ConsultedCampaign c, double amount) {
        int i = 0;
        if ((i = getConsultedCampaigns().indexOf(c)) != -1) {
            getConsultedCampaigns().get(i).addInOfficeHours(amount);
        }
    }

    public void addOutOfOfficeHours(ConsultedCampaign c, double amount) {
        int i = 0;
        if ((i = getConsultedCampaigns().indexOf(c)) != -1) {
            getConsultedCampaigns().get(i).addOutOfOfficeHours(amount);
        }
    }

    public void addConsultedCampaign(ConsultedCampaign cc) {
        if (!consultedCampaigns.contains(cc)) {
            consultedCampaigns.add(cc);
            setChanged();
        }
    }

    public ArrayList<ConsultedCampaign> getConsultedCampaigns() {
        return consultedCampaigns;
    }

    public void setConsultedCampaigns(ArrayList<ConsultedCampaign> campaigns) {
        this.consultedCampaigns = campaigns;
        setChanged();
    }

    public ArrayList<ConsultedCampaign> seeWorkHours() {
        ArrayList<ConsultedCampaign> result = new ArrayList<ConsultedCampaign>();
        for (Iterator<ConsultedCampaign> it = consultedCampaigns.iterator(); it.hasNext();) {
            ConsultedCampaign consultedCampaign = it.next();
            if (consultedCampaign.getCampaign().getStatus().equals(Campaign.ACTIVE)) {
                result.add(consultedCampaign);
            }
        }
        return result;
    }

    public double getInOfficeHours() {
        double result = 0.0;
        for (Iterator<ConsultedCampaign> it = seeWorkHours().iterator(); it.hasNext();) {
            result += it.next().getInOfficeHours();
        }
        return result;
    }

    public double getOutOfOfficeHours() {
        double result = 0.0;
        for (Iterator<ConsultedCampaign> it = seeWorkHours().iterator(); it.hasNext();) {
            result += it.next().getOutOfOfficeHours();
        }
        return result;
    }

    public ArrayList<Campaign> getActiveCampaigns() {
        ArrayList<Campaign> result = new ArrayList<Campaign>();

        for (Iterator<ConsultedCampaign> it = consultedCampaigns.iterator(); it.hasNext();) {
            Campaign c = it.next().getCampaign();
            if (c.getStatus().equals(Campaign.ACTIVE)) {
                result.add(c);
            }
        }
        return result;
    }

    public ArrayList<Campaign> getCampaigns() {

        ArrayList<Campaign> result = new ArrayList<Campaign>();
        for (Iterator<ConsultedCampaign> it = consultedCampaigns.iterator(); it.hasNext();) {
            ConsultedCampaign camp = it.next();
            result.add(camp.getCampaign());
        }
        return result;
    }
}
